package com.extension.company.view.home.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.extension.company.admin.R;
import com.extension.company.common.widget.ShapedImageView;
import com.extension.company.model.api.RetrofitUrlApi;
import com.extension.company.model.entity.RetailGoosListBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 作者:zwk
 * 联系方式：497981239@qq.com
 * 时间：on 2019/7/3 15:02
 * 功能：支付成功后的适配器
 */
public class PaySuccessAdapter extends RecyclerView.Adapter<PaySuccessAdapter.PayAdapter> {


	private Context context;
	private List<RetailGoosListBean.DataBean> retailList;

	public PaySuccessAdapter(Context context, List<RetailGoosListBean.DataBean> retailList) {
		this.context = context;
		this.retailList = retailList;
	}

	@NonNull
	@Override
	public PayAdapter onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
		View view = LayoutInflater.from(context).inflate(R.layout.pay_success_list_item, viewGroup, false);
		return new PayAdapter(view);
	}

	@Override
	public void onBindViewHolder(@NonNull PayAdapter payAdapter, int i) {
		payAdapter.retailGetMoney.setText(retailList.get(i).getCost_price());
		payAdapter.retailTitle.setText(retailList.get(i).getGoods_name());
		payAdapter.retoilMoney.setText(retailList.get(i).getGoods_price());
		RequestOptions requestOptions = new RequestOptions().transform(new RoundedCorners(10));
		Glide.with(context).load(RetrofitUrlApi.BaseHostUrl + retailList.get(i).getImage())
				.apply(requestOptions)
				.into(payAdapter.retailImg);
	}

	@Override
	public int getItemCount() {
		return null == retailList ? 0 : retailList.size();
	}

	class PayAdapter extends RecyclerView.ViewHolder {
		@BindView(R.id.retail_img)
		ShapedImageView retailImg;
		@BindView(R.id.retail_title)
		TextView retailTitle;
		@BindView(R.id.retail_get_money)
		TextView retailGetMoney;
		@BindView(R.id.retoil_money)
		TextView retoilMoney;
		@BindView(R.id.retaim_share)
		ImageView retaimShare;

		private PayAdapter(@NonNull View itemView) {
			super(itemView);
			ButterKnife.bind(this, itemView);
		}
	}
}
